<template>
	<view class="con size29">
		<view class="bgfff ra20 mt30">
			<view @click="setimg" class=" flex-ju-b height100 border-bEDEDED">
				<view class="ml30">头像</view>
				<view class="flex-a-i mr30">
					<image mode="aspectFill" class="wh70-70 image ra70 mr10" :src="avatar?avatar:'/static/mo.png'"></image>
					<uni-icons type="right" size="15" color="#CCCCCC"></uni-icons>
				</view>
			</view>
			<view class="flex-ju-b height100 border-bEDEDED">
				<view class="ml30">昵称</view>
				<view class="flex-a-i color999 size26 mr30">
					<input @blur="confirm" v-model="nickname" confirm-type="done" class="size26 text-right" :placeholder="nickname"/>
					<uni-icons type="right" size="15" color="#CCCCCC"></uni-icons>
				</view>
			</view>
			<view @click="$refs.upfocus.open()" class="flex-ju-b height100 border-bEDEDED">
				<view class="ml30">性别</view>
				<view class="flex-a-i color999 size26 mr30">
					{{sex== 0 ? '未设置' : sex== 1 ? '男':'女'}}
					<uni-icons type="right" size="15" color="#CCCCCC"></uni-icons>
				</view>
			</view>
			<view @click="$refs.upfocus.open()" class="flex-ju-b height100 border-bEDEDED">
				<view class="ml30">版本号</view>
				<view class="flex-a-i color999 size26 mr30">
					 {{version?version:'1.0.0'}}
				</view>
			</view>
		</view>
		
		<view class="bgfff ra20 mt30">
			<view @click="navto('/pages/agreement?guanyu=1')" class="flex-ju-b height100 border-bEDEDED">
				<view class="ml30">关于我们</view>
				<view class="flex-a-i color999 size26 mr30">
					<uni-icons type="right" size="15" color="#CCCCCC"></uni-icons>
				</view>
			</view>
			<view @click="navto('/pages/agreement?yinsi=1')" class="flex-ju-b height100 border-bEDEDED">
				<view class="ml30">隐私协议</view>
				<view class="flex-a-i color999 size26 mr30">
					<uni-icons type="right" size="15" color="#CCCCCC"></uni-icons>
				</view>
			</view>
		</view>
		<view @click="loginlog" class="bgfff flex-ju-c height100 ra50 bold size29 posiab bottom100 width92vw">退出登录</view>
	</view>
	
	
	<uni-popup borderRadius="15px 15px 0 0" background-color="#F5F7F9" ref="upfocus" type="bottom">
		<view class="con pt30 pb50">
			<view @click="setsex(1)" class="bgfff height100 flex-ju-c bold ">
				男
			</view>
			<view @click="setsex(2)" class="bgfff height100 flex-ju-c  bold ">
				女
			</view>
		</view>
	</uni-popup>
	

</template>

<script>
	
	export default {
		data() {
			return {
				version:uni.getStorageSync('version'),
				nickname:uni.getStorageSync('user').nickname,
				avatar:uni.getStorageSync('user').avatar,
				sex:uni.getStorageSync('user').sex
			}
		},
		methods: {
			loginlog(){
				
				
				
				this.http('/api/deal_cid', {
					cid:'',
					uid:uni.getStorageSync('user').uid,
					type:1
				},'post').then(res=>{
					uni.removeStorageSync('token')
					uni.removeStorageSync('user')
					uni.removeStorageSync('uni_id_token')
					uni.reLaunch({
						url:"/pages/login/index"
					})
				}).catch(res=>{
					uni.showModal({
						content:JSON.stringify(res)
					})
				})
				
			},
			confirm(){
				if(this.nickname.trim()){
					this.http('/api/user/edit',{
						nickname:this.nickname
					},'post').then(ress=>{
						this.nickname = this.nickname
						var urd = uni.getStorageSync('user')
							urd.nickname = this.nickname
						uni.setStorageSync('user',urd)
						 
					})
				}
			},
			setsex(sex){
				this.http('/api/user/edit',{
					sex
				},'post').then(ress=>{
					this.sex = sex
					var urd = uni.getStorageSync('user')
						urd.sex = sex
					uni.setStorageSync('user',urd)
					this.$refs.upfocus.close()
				})
			},
			setimg(){
				this.upimg(1).then(res=>{
					this.http('/api/user/edit',{
						avatar:res[0]
					},'post').then(ress=>{
						this.avatar = res[0]
						var urd = uni.getStorageSync('user')
							urd.avatar = res[0]
						uni.setStorageSync('user',urd)
						this.imimg()
					})
				})
			},
			imimg(){
				this.http('/api/get_auth_secret', {
					account: uni.getStorageSync('user').phone,
					password: 'fciu123456',
					type:1,
					nickname:'u'+uni.getStorageSync('user').phone,
					externalUid: uni.getStorageSync('user').uid + '',
				}, 'post','isload').then(res => {
					uni.request({
						url: 'https://fc-mp-f01b0fd2-90b7-4af3-a7a6-7983b23df550.next.bspapp.com/uni-id-co/updateUserInfoByExternal',
						data: {
							clientInfo: uni.getSystemInfoSync(),
							"uniIdToken": uni.getStorageSync('uni_id_token'),
							params: {
								avatar:this.avatar
							}
						},
						method: 'POST',
						header: {
							'Cache-Control': 'no-cache',
							'uni-id-nonce': res.data.nonce,
							'uni-id-timestamp': res.data.timestamp,
							'uni-id-signature': res.data.signature,
							'content-Type': 'application/json'
						},
						success: (res) => {
							
						}
					})
				})
			}
		}
	}
</script>

<style>
page{
	background: #F6F7F8;
}
</style>
